package com.tools.cleanmaster.ui.card;

import android.app.Activity;
import android.view.View;
import android.widget.Toast;

import com.swipe.SwipeMgr;
import com.tools.ad.EntranceType;
import com.tools.cleanmaster.CleanApplication;
import com.tools.cleanmaster.R;
import com.tools.cleanmaster.ui.card.factory.CardListAdapter;
import com.tools.cleanmaster.ui.card.viewholder.ACardViewHolder;
import com.tools.cleanmaster.ui.card.viewholder.CommonCardViewHolder;
import com.tools.cleanmaster.ui.view.ToastHelper;

public class SwipeCardItem extends ACardItem {

    public SwipeCardItem(EntranceType entranceType, int pos) {
        super(entranceType, pos);
    }

    @Override
    public CardViewType getCardViewType() {
        return CardViewType.SWIPE;
    }

    @Override
    public boolean needShow(EntranceType entranceType) {
        boolean needShow = false;
        try {
            needShow = SwipeMgr.getInstance().isSwipeEnable() && imContext.getADModule().isOrganicOrOtherChannel()
                    && !imContext.getADModule().getADSharedPrefManager().getSwipeAdEnable();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return needShow;
    }

    @Override
    public String getCardName() {
        return CardType.SWIPE.key;
    }

    @Override
    public void bindCardView(final Activity activity, ACardViewHolder viewHolder, final CardListAdapter cardAdapter, final int position) {
        super.bindCardView(activity, viewHolder, cardAdapter, position);
        CommonCardViewHolder holder = (CommonCardViewHolder) viewHolder;
        holder.mLogo.setImageResource(R.drawable.card_func_swipe);
        holder.mTitle.setText(activity.getString(R.string.du_swipe_settting_title));
        holder.mDesc.setText(activity.getString(R.string.du_swipe_settting_desc));
        holder.mExecute.setText(R.string.screen_card_btn_txt);

        holder.mExecute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doClick(activity, cardAdapter, position);
            }
        });
        holder.mItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doClick(activity, cardAdapter, position);
            }
        });

    }

    private void doClick(Activity activity, CardListAdapter adapter, int position) {
        imContext.getADModule().getADSharedPrefManager().setSwipeAdEnable(true);
        ToastHelper.create(CleanApplication.getInstance(), activity.getText(R.string.swipe_guide_card_open_success_toast), Toast.LENGTH_LONG).show();
        adapter.dismissAnimation(position);
    }
}
